<!--
	作者：offline
	时间：2019-01-29
	描述：内容详情
-->
<template>
  <div class="m-view-noticeDetailsComponent m-window">
    <el-button @click="cancel">返回</el-button>
    <el-card class="box-card2">
      <div slot="header" class="clearfix">
        <p style="text-align: center;font-size: 20px;">{{title}}</p>
        <div style="text-align: center;">
          <p style="display:inline;">创建人：{{creator}}</p>
          <p style="display:inline;">{{createDate}}</p>
        </div>
      </div>
      <p style="padding-left: 5px;" v-html="content"></p>
    </el-card>
    <div class="noticeFile">
      <div>
        附件：
        <el-row :gutter="4">
          <el-col
            v-for="item in attachmentList"
            :key="item.ID"
            :label="item.name"
            :value="item.url"
            :span="4"
          >
            <el-tooltip class="item" effect="dark" :content="item.name" placement="top">
              <p
                style="font-size:16px; color:blue; text-decoration:underline; cursor:pointer;white-space: nowrap;"
                @click="downLoadFile(item)"
                class="filesName"
              >{{item.name.length>16?`${item.name.substring(0,4)}....${item.name.substring(item.name.length-7,item.name.length)}`:item.name}}</p>
            </el-tooltip>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
import _Api from "@/api";
import downLoadFileFunc from "@/public/downLoadFile"
export default {
  data () {
    return {
      title: "",
      creator: "",
      createDate: "",
      content: "",
      createDateFormat: "",
      attachmentList: []
    }
  },
  methods: {
    downLoadFile (params) {
      var obj = {};
      obj.viewPath = params.url;
      obj.groupName = 'TEST';
      obj.fileName = ''
      if (params.url.indexOf('SRM') > -1) {
        obj.groupName = 'SRM'
      } else if (params.url.indexOf('SIGN') > -1) {
        obj.groupName = 'SIGN'
      } else if (params.url.indexOf('TEST') > -1) {
        obj.groupName = 'TEST'
      }
      downLoadFileFunc(obj, params.name)
      //   _Api.getFilePath(obj).then(function (response) {
      //     var data = response.data;
      //     if (data.code == "200") {
      //       that.downLoad(data.data, params.name);
      //     }
      //   })
    },
    downLoad (url, filename) {
      var eleLink = document.createElement('a');
      eleLink.style.display = 'none';
      eleLink.setAttribute("href", url);   //文件下载地址
      eleLink.setAttribute("download", filename);  //download属性只能在同域实现
      // 触发点击
      document.body.appendChild(eleLink);
      eleLink.click();
      // 然后移除
      document.body.removeChild(eleLink);
    },
    cancel: function () {
      this.$emit("cancelComponents", true);
    },
  },
  mounted () {
    if (this.setClickValue) {
      this.title = this.setClickValue.title;
      this.creator = this.setClickValue.creator;
      this.createDate = this.setClickValue.createDate;
      this.content = this.setClickValue.content;
      this.attachmentList = this.setClickValue.attachmentList;
      this.createDateFormat = new Date(this.setClickValue.createDate).Format("yyyy-MM-dd")
    }
  },
  props: ['setClickValue']
}
</script>

<style>
</style>